 /*
 Kyle Kelly
 CS2110-B2 HW9
 General lib for HW9
 */
#include "DMATesting.h"

u16 *videoBuffer = (u16 *)0x6000000;

void setPixel(int r, int c, u16 color){
	videoBuffer[OFFSET(r,c, SCREENW)] = color;
}

void waitForVblank(){
	while(SCANLINECOUNTER>160);
	while(SCANLINECOUNTER<160);
}

void drawImage3(int r, int c, int height, int width, const u16* image)
{
    for (int row = 0; row < height; row++)
    {
        REG_DMA3SAD = (vu32)&image[width*row];
        REG_DMA3DAD = (vu32)&videoBuffer[(row+r)*240+c];
        REG_DMA3CNT = width | DMA_ON;
    }
}



void drawRect(int row, int col, int height, int width, u16 color)
{
	int r;
	for(r=0; r<height; r++)
	{
		REG_DMA3SAD = (vu32)&color;
		REG_DMA3DAD = (vu32)(videoBuffer + OFFSET(row+r, col, SCREENW));
        REG_DMA3CNT = width | DMA_ON | DMA_SOURCE_FIXED;
	}
}

void everyOtherPixel(u16 color)
{
    
}
